<?php
    /**
    * @framework : My Framework
    *
    * @author: fatangel26@gmail.com - Nguyễn Bảo Trung.
    *
    */

    class my_controller
	{

        public $_model;

        public $_helper;

        protected $_data;

        public function __construct()
        {

            $this->_helper                  = new helper_session();

            $this->_data['navbar'] 			= $this->_display_navbar();
            $this->_data['intro'] 			= $this->_display_intro();
            $this->_data['news_hightlight'] = $this->_display_news_hightlight();
            $this->_data['search_box'] 		= $this->_display_search_box();
            $this->_data['support'] 		= $this->_display_support();
            $this->_data['cart'] 			= $this->_display_cart();
            $this->_data['main_left'] 		= $this->_display_main_left();
			$this->_data['bottom_slide'] 	= $this->_display_bottom_slide();
            $this->_data['footer'] 			= $this->_display_footer();
            $this->_data['slide'] 			= $this->_display_slide();
        }

        public function view ($path, $data, $layout = FALSE)
        {
            if(isset($data) && is_array($data) && !empty($data))
                extract($data);

            if($layout == TRUE)
            {
                ob_start();
                require("views/".$path.".php");

                $strView = ob_get_contents();
                ob_end_clean();
                return $strView;
            }
            else
            {
                include("views/".$path.".php");
            }
        }

        public function redirect($path)
        {
            if(isset($path) && is_string($path))
                header("location: ".$path);
        }

        /************LOAD BLOCK DEFAULT*************/
        public function _display_navbar()
        {
            $output = '';

			$this->_model = new model_navbar();

			$data['navbars'] = $this->_model->getNav();

            $output = $this->view('includes/navbar', $data, TRUE);

            return $output;

        }//End function display_navbar()

        public function _display_intro()
        {
            $output = '';

			$this->_model = new model_cms();

			$data['intro'] = $this->_model->getIntro();

            $output = $this->view('includes/intro', $data, TRUE);

            return $output;
        }//End function display_intro()

        public function _display_slide()
        {
            $output = '';

            /*LOAD HELPER AUTOMATIC*/
            $this->_helper  = new helper_text();

            $this->_model   = new model_slide();

            $data['slides'] = $this->_model->getSlide();

            $output         = $this->view('includes/slide', $data, TRUE);

            return $output;
        }//End function display_slide()


        public function _display_news_hightlight()
        {
            $output = '';

            /*LOAD HELPER AUTOMATIC*/
            $this->_helper = new helper_text();

            $this->_model  = new model_news();

            $data['news']  = $this->_model->getNews();

            $output        = $this->view('includes/hightlight', $data, TRUE);

            return $output;
        }//End function display_news_hightlight()

        public function _display_search_box()
        {
            $output        = '';

            $this->_model  = new model_menu();

            $data['menus'] = $this->_model->getMenuSearch();

            $output        = $this->view('includes/search', $data, TRUE);

            return $output;
        }//End function display_search_box()

        public function _display_support()
        {
            $output = '';

            $output = $this->view('includes/support', $data = '', TRUE);

            return $output;
        }//End function display_support()

        public function _display_cart()
        {
            $output        = '';

            $this->_helper = new helper_session();

            $output        = $this->view('includes/cart', $data = '', TRUE);

            return $output;
        }//End function display_cart()


        public function _display_main_left()
        {
            $output = '';

            /*LOAD HELPER AUTOMATIC*/
            $this->_helper = new helper_text();

            /*LOAD MODEL AUTOMATIC*/
			$this->_model->product  = new model_product();
            $this->_model->menu     = new model_menu();
            $this->_model->counter  = new model_counter();

            /*SEND DATA TO VIEW*/
            $data['hotproduct']  = $this->_model->product->getHotproduct();

            $menus               = $this->_model->menu->getAllMenu();

			$data['tree_menus']  = $this->_model->menu->buildTreeMenus($menus, $parent_id = 0);

            $data['user_online'] = $this->_model->counter->getUserOnline();
            $data['user_counter']= $this->_model->counter->getCounter();


            $output = $this->view('includes/main_left', $data, TRUE);

            return $output;
        }//End function display_main_left()

        public function _display_bottom_slide()
        {
            $output        = '';

            $this->_model  = new model_cms();

            $data['links'] = $this->_model->getBottomSlide();

            $output        = $this->view('includes/bottom_slide', $data, TRUE);

            return $output;
        }//End function display_bottom_slide()

        public function _display_footer()
        {
            $output          = '';

            $this->_model    = new model_cms();

            $data['footer']  = $this->_model->getFooter();

            $this->_model    = new model_navbar();

            $data['navbars'] = $this->_model->getNav();

            $output          = $this->view('includes/footer', $data, TRUE);

            return $output;
        }//End function display_footer()


    }

    /* End of file my_controller.php */
    /* Location: .//D/root/my_framework/core/my_controller.php */

